package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.BusinessSystemMenuEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 业务系统菜单Provider
 *
 * @author generator
 * @date 2020-03-18 15:10
 */
public class BusinessSystemMenuProvider {

    /**
     * 增加BusinessSystemMenu
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-18 15:10
     */
    public String insertBusinessSystemMenu(@Param("entity") BusinessSystemMenuEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" business_system_menu ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_system_id ", " #{entity.businessSystemId,jdbcType=INTEGER} ");
                VALUES(" parent_id ", " #{entity.parentId,jdbcType=INTEGER} ");
                VALUES(" menu_name ", " #{entity.menuName,jdbcType=VARCHAR} ");
                VALUES(" menu_route ", " #{entity.menuRoute,jdbcType=VARCHAR} ");
                VALUES(" menu_redirect_route ", " #{entity.menuRedirectRoute,jdbcType=VARCHAR} ");
                VALUES(" menu_icon ", " #{entity.menuIcon,jdbcType=VARCHAR} ");

                if (entity.getDisableState() != null) {
                    VALUES(" disable_state ", " #{entity.disableState,jdbcType=TINYINT} ");
                }

                VALUES(" sort ", " #{entity.sort,jdbcType=INTEGER} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改BusinessSystemMenu
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-18 15:10
     */
    public String updateBusinessSystemMenu(@Param("entity") BusinessSystemMenuEntity entity) {
        return new SQL() {
            {
                UPDATE(" business_system_menu ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_system_id = #{entity.businessSystemId,jdbcType=INTEGER} ");
                SET(" parent_id = #{entity.parentId,jdbcType=INTEGER} ");
                SET(" menu_name = #{entity.menuName,jdbcType=VARCHAR} ");
                SET(" menu_route = #{entity.menuRoute,jdbcType=VARCHAR} ");
                SET(" menu_redirect_route = #{entity.menuRedirectRoute,jdbcType=VARCHAR} ");
                SET(" menu_icon = #{entity.menuIcon,jdbcType=VARCHAR} ");

                if (entity.getDisableState() != null) {
                    SET(" disable_state = #{entity.disableState,jdbcType=TINYINT} ");
                }

                SET(" sort = #{entity.sort,jdbcType=INTEGER} ");
                SET(" remark = #{entity.remark} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询BusinessSystemMenu列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-18 15:10
     */
    public String listBusinessSystemMenu(@Param("entity") BusinessSystemMenuEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_system_id,parent_id,menu_name,menu_route,menu_redirect_route,menu_icon,disable_state,sort,remark,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" business_system_menu ");

                if (entity.getBusinessSystemId() != null) {
                    WHERE(" business_system_id = #{entity.businessSystemId,jdbcType=INTEGER} ");
                }

                if (entity.getParentId() != null) {
                    WHERE(" parent_id = #{entity.parentId,jdbcType=INTEGER} ");
                }

                if (entity.getMenuName() != null) {
                    WHERE(" menu_name = #{entity.menuName,jdbcType=VARCHAR} ");
                }

                if (entity.getMenuRoute() != null) {
                    WHERE(" menu_route = #{entity.menuRoute,jdbcType=VARCHAR} ");
                }

                if (entity.getMenuRedirectRoute() != null) {
                    WHERE(" menu_redirect_route = #{entity.menuRedirectRoute,jdbcType=VARCHAR} ");
                }

                if (entity.getMenuIcon() != null) {
                    WHERE(" menu_icon = #{entity.menuIcon,jdbcType=VARCHAR} ");
                }

                if (entity.getDisableState() != null) {
                    WHERE(" disable_state = #{entity.disableState,jdbcType=TINYINT} ");
                }

                if (entity.getSort() != null) {
                    WHERE(" sort = #{entity.sort,jdbcType=INTEGER} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}